<template>
  <div class="center">
    <div class="title"><img src="~/assets/images/quick-entry.png" alt="" />快捷入口</div>
    <div class="entry">
      <div class="item" v-for="(item, index) in category" :key="index">
        <div class="pic">
          <img :src="item.image" class="object" />
        </div>
        <div class="name">{{ item.info }}</div>
        <div class="links">
          <div
            v-for="(item2, index2) in item.menu"
            :key="index2"
            @click="goList(item2.article_category_id)"
            class="link cursor"
          >
            {{ item2.info }}
          </div>
        </div>
      </div>
    </div>

    <div class="title"><img src="~/assets/images/quick-entry.png" alt="" />热门问题</div>
    <div class="question">
      <div class="search">
        <m-searchbar
          width="376px"
          v-model.trim="keywords"
          placeholder="请简单描述您的问题，如“会员权益”"
          @click-search="search"
        />
        <m-button
          class="all transition"
          width="134"
          height="40"
          @click="goList(category[0].menu[0].article_category_id)"
          >查看全部 
          <i class="el-icon-arrow-right"></i>
        </m-button>
      </div>
      <div class="list">
        <p
          class="item"
          v-for="(item, index) in hot"
          :key="index"
          @click="goDetail(item.article_id)"
        >
          {{ item.title }}
        </p>
        <nodata message="未搜索到数据" :status="listStatus"></nodata>
      </div>
    </div>
  </div>
</template>

<script>
import MSearchbar from "@/components/m-searchbar/MSearchbar"
import MButton from "@/components/common/m-button/MButton"
import { getCategory2, getHelpHot, helpSearch } from "@/request/api"
import { Icon } from 'element-ui'
import Vue from 'vue'
Vue.use(Icon)

export default {
  name: "Center",
  components: { MButton, MSearchbar },
  data() {
    return {
      category: "",
      keywords: "",
      hot: [],
      listStatus: 3
    }
  },
  created() {
    this.getCate()
    this.getHot()
  },
  methods: {
    getCate() {
      getCategory2(0).then((res) => {
        this.category = res.data
      }).catch(err => {
        this.$toastVant.fail(err.message)
      })
    },
    getHot() {
      getHelpHot().then((res) => {
        this.hot = res.data
      }).catch(err => {
        this.$message.error(err.message)
      })
    },
    goList(id) {
      this.$router.push({ name: "HelpCenterList", query: { id: id } })
    },
    goDetail(id) {
      this.$router.push({ name: "HelpCenterList", query: { art: id } })
    },
    search() {
      if (!this.keywords) {
        return this.$toastVant.fail("请输入关键词")
      }
      this.listStatus = 1
      helpSearch(this.keywords).then((res) => {
        if (res.data.length === 0) {
          this.listStatus = 0
        } else {
          this.listStatus = 2
        }
        this.hot = res.data
      }).catch(err => {
        this.listStatus = 0
        this.$message.error(err.message)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/assets/style/common.scss";
@import "~@/assets/style/base.css";
/deep/ .el-input__inner {
  background: none;
}
/deep/ .el-input-group__prepend {
  background-color: transparent !important;
}
.center {
  .title {
    display: flex;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 30px;

    img {
      margin-right: 15px;
    }
  }

  .entry {
    display: flex;
    background-color: #fff;
    padding: 15px;
    margin: -10px;
    margin-bottom: 30px;

    .item {
      width: calc((100% - 80px) / 4);
      height: 388px;
      margin: 10px;
      background-color: rgb(243, 244, 247);
      border: solid 1px #eaeaea;
      display: inline-flex;
      flex-direction: column;
      align-items: center;
      padding: 15px;
      font-size: 16px;
      color: #666;

      .pic {
        width: 140px;
        height: 140px;
        border-radius: 155px;
        border: solid 6px #fff;
        margin-bottom: 15px;
        background-color: pink;
        overflow: hidden;
      }

      .name {
        font-weight: bold;
        font-size: 18px;
        margin-bottom: 30px;
      }

      .links {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 90%;

        .link {
          padding-bottom: 6px;
          margin-bottom: 7px;
          border-bottom: 1px solid #dfdfdf;
          width: 65%;
          text-align: center;
          &:hover {
            color: $theme-color-1;
          }
        }
      }
    }
  }

  .question {
    background-color: #fff;
    padding: 30px 15px;
    margin: -10px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: url("~@/assets/images/help.jpg") no-repeat;
    background-size: cover;
    .search {
      display: flex;
      justify-content: center;
      margin-bottom: 30px;

      .all {
        position: absolute;
        right: 100px;
        border-radius: 30px;
        overflow: hidden;
        &:hover {
          opacity: 0.8;
        }
      }
    }

    .list {
      width: 1100px;
      color: #666;
      font-size: 16px;
      display: flex;
      flex-wrap: wrap;
      .item {
        width: 33.3%;
        padding: 0 10px;
        overflow: hidden;
        margin-bottom: 30px;
        text-align: center;
        cursor: pointer;
        &:hover {
          color: $theme-color-1;
        }
      }
    }
  }
}
</style>